﻿using System;
using System.Collections.Generic;

namespace CtpTrader.Core.Quote
{
    /// <summary>
    /// K线数据结构
    /// </summary>
    public class Bar
    {
        public Bar(DateTime openTime, double price)
        {
            this.Open   = price;
            this.High   = price;
            this.Low    = price;
            this.Close  = price;

            this.OpenTime = openTime;
        }

        /// <summary>
        /// K线开始时间
        /// </summary>
        public DateTime OpenTime { get; set; }

        /// <summary>
        /// 最高价
        /// </summary>
        public double High { get; set; }

        /// <summary>
        /// 最低价
        /// </summary>
        public double Low { get; set; }

        /// <summary>
        /// 开盘价
        /// </summary>
        public double Open { get; set; }

        /// <summary>
        /// 收盘价
        /// </summary>
        public double Close { get; set; }

        /// <summary>
        /// 成交量
        /// </summary>
        public long Volume { get; set; }

        /// <summary>
        /// 设置K线最新价格并更新最高和最低价格
        /// </summary>
        /// <param name="price">最新价格</param>
        public void UpdatePrice(double price)
        {
            this.Close = price;

            if (this.Close > this.High) this.High = this.Close;
            if (this.Close < this.Low)  this.Low  = this.Close;
        }
    }
}
